<!DOCTYPE html>
<html>
<head>
    <title>Sending Funds - Lotus Fountain</title>
    <link rel="stylesheet" type="text/css" href="main.css">
</head>
<body>
<div class="Index">
    <div class="Index-nodes">
        <div class="Index-node">
            [CREATING STORAGE MINER]
        </div>
        <div class="Index-node">
            Gas Funds:&nbsp;&nbsp;&nbsp;<span id="fcid"></span> - <span id="fstate">WAIT</span>
        </div>
        <div class="Index-node">
            Miner Actor:&nbsp;<span id="mcid"></span> - <span id="mstate">WAIT</span>
        </div>
        <div class="Index-node" style="display: none" id="fwait">
            New storage miners address is: <b id="actaddr">t</b>
        </div>
        <div class="Index-node" style="display: none" id="mwait">
            <div style="padding-bottom: 1em">To initialize the storage miner run the following command:</div>
            <div style="overflow-x: visible; white-space: nowrap; background: #353500">
                <code>lotus-storage-miner init --actor=<span id="actaddr2">t</span> --owner=<span id="owner">t3</span></code>
            </div>
        </div>
    </div>
    <div class="Index-footer">
        <div>
            <a href="index.html">[Back]</a>
            <span style="float: right">Not dispensing real Filecoin tokens</span>
        </div>
    </div>
</div>
<script>
  const params = new URLSearchParams(window.location.search);

  const fcid = document.getElementById('fcid')
  const mcid = document.getElementById('mcid')

  fcid.innerText = params.get('f')
  mcid.innerText = params.get('m')

  async function waitFunds() {
    await fetch('/msgwait?cid=' + params.get('f'))
    document.getElementById('fstate').innerText = "OK"

    document.getElementById('fwait').style.display = 'block'
  }

  async function waitMiner() {
    const resp = await fetch('/msgwaitaddr?cid=' + params.get('f'))
    document.getElementById('mstate').innerText = "OK"

    const addr = (await resp.json()).addr

    document.getElementById('actaddr').innerText = addr
    document.getElementById('actaddr2').innerText = addr
    document.getElementById('owner').innerText = params.get('o')

    document.getElementById('mwait').style.display = 'block'
  }

  waitFunds()
  waitMiner()
</script>
</body>
</html>
